package com.dfdchem.imd.kaiwu.util;

import android.webkit.MimeTypeMap;

import java.io.File;

public class FileUtil {

    public static String getFileName(String filePath){

        int start = filePath.lastIndexOf("/");
        int end = filePath.lastIndexOf(".");
        if(start != -1 && end != -1){
            return filePath.substring(start+1, end);
        }else{
            return null;
        }
    }

    public static String getFileFullName(String filePath){

        int start = filePath.lastIndexOf("/");
        if(start != -1){
            return filePath.substring(start+1, filePath.length());
        }else{
            return null;
        }
    }

    public static long getFileSize(String filePath){

        File file = new File(filePath);
        return file.length();
    }

    public static String getMimeType(String filePath) {
        String ext = MimeTypeMap.getFileExtensionFromUrl(filePath);
        return MimeTypeMap.getSingleton().getMimeTypeFromExtension(ext);
    }
}